Ext.ns("CRM.SPComp");

(function() {

	CRM.SPComp.createReportMenu = function() {
		
		function redirectPageTo(absoluteUrl, salesSubTabActiveTabIndex){
			var newPath = absoluteUrl;
			var currentUrl = window.location.href;
			var currentPath = currentUrl.substring(currentUrl.lastIndexOf("/")+1, currentUrl.length);
			if(currentPath != newPath){
				window.location = newPath;
				}
				salesTab.setActiveTab(salesSubTabActiveTabIndex);
				//subTab.setActiveTab(subTabIndex);
		};			
		
		var subRootPanel = {
        		xtype		: 'panel',
        		id			: 'subRootPanel',
            	tbar		: {
			            		xtype       : 'toolbar',
			                    items       : [
												{
												    xtype   : 'tbbutton',
												    id		: 'activityMenu',
												    text    : 'Activity',
												    menu	: [
												        	   {
												        		   text	: 'Open Activities',
												        		   handler : function(){
												        			   			redirectPageTo('activityreports', 7);
																			}
												        	   },
												        	   {
												        		   text	: 'All Activities'
												        	   }
												        	  ]
												},
												'-',
												{
						                            xtype   : 'tbbutton',
						                            id		: 'opportunityMenu',
						                            text    : 'Opportunity',
						                            menu	: [
						                                	   {
						                                		   text    : 'Open Opportunities',
						                                		   handler : function(){
						                                		        redirectPageTo('opportunityreports',7);
						                                	       }
						                                	   },
						                                	    {
						                                	    	text : 'All Opportunites'
						                                	    }
						                                	   ]
						                        },
												'-',           
						                        {
						                            xtype   : 'tbbutton',
						                            id		: 'leadMenu',
						                            text    : 'Lead',
						                            menu	: [
						                                	    {
						                                			text : 'All Leads'   
						                                	    }
						                                	   ]
						                         },
												 '-'
			                    				]
            				  }
        	};
		return subRootPanel;
	};	

})();